package cn.sdormitory.knowledgebase.vo;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Data
public class StudyQuestionsVo {
    private Integer id;           // 主键
    private String content;       // 题目内容
    private Integer type;         // 题目类型 1:单选 2:多选 3:判断 4:填空
    private String option;        // 选项
    private String answer;        // 答案
    private Integer score;        // 题目分值
    private String analysis;      // 题目解析
    private String createTime;    // 创建时间
    private String modifyTime;    // 修改时间
    private String userAnswer;    // 用户答案
    private Boolean isCorrect;    // 是否正确

    // 封装选项的对象列表
    private List<Map<String, Object>> optionList = new ArrayList<>();

    // 解析 JSON 字符串到 optionList 中
    public void parseOption() {
        if (this.option != null) {
            ObjectMapper objectMapper = new ObjectMapper();
            try {
                this.optionList = objectMapper.readValue(this.option, new TypeReference<List<Map<String, Object>>>() {});
            } catch (Exception e) {
                e.printStackTrace();
                this.optionList = new ArrayList<>();
            }
        }
    }

}
